﻿using FluentMigrator;
using Smartstore.Core.Identity;
using Smartstore.Core.Stores;

namespace Smartstore.Core.Data.Migrations
{
    [MigrationVersion("2024-10-08 10:37:00", "Core: StoreSync")]
    internal class StoreSync : Migration
    {
        public override void Up()
        {
            var tableName = nameof(Store);
            var syncYLQXEnabled = nameof(Store.SyncYLQXEnabled);
            var syncYLQXPageSize = nameof(Store.SyncYLQXPageSize);
            var syncYLQXProductUrl = nameof(Store.SyncYLQXProductUrl);
            var syncYLQXProductId = nameof(Store.SyncYLQXProductId);
            var syncYLQXStockUrl = nameof(Store.SyncYLQXStockUrl);
            var syncYLQXStockId = nameof(Store.SyncYLQXStockId);

            if (!Schema.Table(tableName).Column(syncYLQXEnabled).Exists())
            {
                Create.Column(syncYLQXEnabled).OnTable(tableName).AsBoolean().NotNullable().WithDefaultValue(0);
            }

            if (!Schema.Table(tableName).Column(syncYLQXPageSize).Exists())
            {
                Create.Column(syncYLQXPageSize).OnTable(tableName).AsInt32().NotNullable().WithDefaultValue(0);
            }

            if (!Schema.Table(tableName).Column(syncYLQXProductUrl).Exists())
            {
                Create.Column(syncYLQXProductUrl).OnTable(tableName).AsString(400).Nullable();
            }

            if (!Schema.Table(tableName).Column(syncYLQXProductId).Exists())
            {
                Create.Column(syncYLQXProductId).OnTable(tableName).AsInt32().NotNullable().WithDefaultValue(0);
            }

            if (!Schema.Table(tableName).Column(syncYLQXStockUrl).Exists())
            {
                Create.Column(syncYLQXStockUrl).OnTable(tableName).AsString(400).Nullable();
            }

            if (!Schema.Table(tableName).Column(syncYLQXStockId).Exists())
            {
                Create.Column(syncYLQXStockId).OnTable(tableName).AsInt32().NotNullable().WithDefaultValue(0);
            }
        }

        public override void Down()
        {
        }
    }
}
